/* 
 * File:   Visualizer.h
 * Author: cjjonker
 *
 * Created on 20 december 2012, 15:06
 */

#ifndef VISUALIZER_H
#define	VISUALIZER_H

#include <string>
#include "ColorLegend.h"
#include "ColorMap.h"
#include "Simulation.h"

class Visualizer {
    
    bool d_isactive;
        
    public:
        Visualizer();
        Visualizer(std::string &name);
        
        void setColormapMinMax(int slices, int sliceDT);

        void toggleActive();
        bool isActive();
        
        int timeslices();
        void timeslices(int i);
        
        void setNormalize(int n);
        
        void setActive(bool a);
        void setSimulation(Simulation *sim);
        
        void setCurrentAppearance(int id);
        
        void setCurrentMapDataset();
        void setCurrentMapDataset(int id);
        
        void setCurrentAlphaDataset();
        void setCurrentAlphaDataset(int id);
        
        void setCurrentMapColormode(int id);
        void setCurrentMapScalemode(int id);
        
        void setCurrentMapClampMin(double m);
        void setCurrentMapClampMax(double m);
                
        void setCurrentVectorDataset();
        void setCurrentVectorDataset(int id);
        
        void setVectorScale(double s);
        
        void setColormapHue(float h);
        void setColormapSat(float s);
        void setColormapVal(float v);
        void setColormapLevels(float l);
        float getColormapHue();
        float getColormapSat();
        float getColormapVal();
        float getColormapLevels();
        
        bool usesColormap();
        bool usesVectorDataset();
        bool hasMultipleAppearances();
        
        void setXGridSize(int xs);
        void setYGridSize(int ys);
        
        int getXGridSize() const;
        int getYGridSize() const;
        
        void setUsesAlpha(bool uses);
        bool getUsesAlpha() const;
        
        void setGlobalAlpha(float alpha);
        float getGlobalAlpha() const;
        
        std::string getName();
        
        std::vector<std::string> getColormapDatasets();
        std::vector<std::string> getColorModeNames();
        std::vector<std::string> getScaleModeNames();
        std::vector<std::string> getVectorDatasetNames();
        std::vector<std::string> getAppearancesNames();
        
        virtual void draw(float winW, float winH);
        virtual void draw(float winW, float winH, int t);
        virtual void draw(float winW, float winH, int t, int slices, int sliceDT)=0;        
        void drawLegend(double x, double y, float winW, float winH, int dim);
        virtual void removeAllSeeds();
        virtual void seedGrid();

    protected: 
        enum ColorMapDatasets
        {
            Rho,V,F,GradientMagnitudeRho,GradientMagnitudeV,AngleV,AngleF,GradientAngleRho,GradientAngleV,ColorMapDatasetsCount
        };
        
        enum VectorDatasets
        {
            Flow, Force, GradientRho, GradientV, DatasetCount
        };
                
        virtual void init();
        
        ScalarDataset *d_map_dataset;
        ScalarDataset *d_alpha_dataset;
        
        VectorDataset *d_vector_dataset;
        int d_current_vector_dataset_index;
        
        int d_appearance;
        
        float d_global_alpha;
        
        Simulation *d_simulation;
        std::string d_name;
        ColorLegend d_legend;
        ColorMap d_map;
        
        bool d_uses_colormap;
        bool d_uses_vector_dataset; //if this visualizer uses a dataset other than colormap
        
        bool d_has_multiple_appearances;
        
        double d_scale;
        
        int d_timeslices;        

        int d_xGridSize;
        int d_yGridSize;
        
        bool d_normalize;
        bool d_initran;
        
        bool d_uses_alpha;

        void setColormapMinMax();
        void setGLColor(int idx);
        void setGLColor(int idx, int t);
        void setGLColor(float x, float y);

        void setGLColor(float x, float y, int t);
        void setName(std::string const &str); 
        
        float totalAlpha(int idx, int t);
        float totalAlpha(float x, float y, int t);
        
        int d_current_map_dataset_index;        
        int d_current_alpha_dataset_index;
        std::vector<std::string> d_map_dataset_names;
        std::vector<std::string> d_vector_dataset_names;
        std::vector<std::string> d_multiple_appearances;

    private:

};

inline void Visualizer::setColormapMinMax() { setColormapMinMax(1,1); }

inline void Visualizer::draw(float winW, float winH) { draw(winW, winH, 0); }

inline void Visualizer::draw(float winW, float winH, int t) { draw(winW, winH, t, 1,1); }

inline bool Visualizer::usesColormap() { return d_uses_colormap; }

inline void Visualizer::toggleActive() { d_isactive = !d_isactive; }

inline void Visualizer::setActive(bool a) { d_isactive = a; }

inline bool Visualizer::isActive() { return d_isactive; }

inline void Visualizer::setSimulation(Simulation *sim) { d_simulation = sim; init(); }

inline std::string Visualizer::getName() { return d_name; }

inline std::vector<std::string> Visualizer::getColormapDatasets() { return d_map_dataset_names; }

inline std::vector<std::string> Visualizer::getColorModeNames() { return d_map.colorModeNames(); }

inline std::vector<std::string> Visualizer::getScaleModeNames() { return d_map.scaleModeNames(); }

inline void Visualizer::setCurrentMapColormode(int id) { d_map.colorMode(id); }

inline void Visualizer::setCurrentMapScalemode(int id) { d_map.scaleMode(id); }

inline bool Visualizer::usesVectorDataset() { return d_uses_vector_dataset; }

inline std::vector<std::string> Visualizer::getVectorDatasetNames() { return d_vector_dataset_names; }

inline std::vector<std::string> Visualizer::getAppearancesNames() { return d_multiple_appearances; }

inline void Visualizer::setColormapSat(float s) { d_map.saturation(s); }

inline void Visualizer::setColormapVal(float v) { d_map.value(v); }

inline void Visualizer::setColormapHue(float h) { d_map.hue(h); }

inline void Visualizer::setColormapLevels(float l) { d_map.levels(l); }

inline float Visualizer::getColormapHue() { return d_map.hue(); }

inline float Visualizer::getColormapSat() { return d_map.saturation(); }

inline float Visualizer::getColormapLevels() { return d_map.levels(); }

inline float Visualizer::getColormapVal() { return d_map.value(); }

inline bool Visualizer::hasMultipleAppearances() { return d_has_multiple_appearances; }

inline int Visualizer::timeslices() {return d_timeslices; }

inline void Visualizer::timeslices(int i) { d_timeslices = i; }

inline void Visualizer::setNormalize(int n) { d_normalize = n; }

inline void Visualizer::setCurrentMapClampMax(double m) { d_map.clampMax(m); }

inline void Visualizer::setCurrentMapClampMin(double m) { d_map.clampMin(m); }

inline void Visualizer::setVectorScale(double s) { d_scale = s; }

inline void Visualizer::setXGridSize(int xs)
{
    d_xGridSize = xs;
}

inline void Visualizer::setYGridSize(int ys)
{
    d_yGridSize = ys;
}

inline int Visualizer::getXGridSize() const
{
    return d_xGridSize;
}

inline int Visualizer::getYGridSize() const
{
    return d_yGridSize;
}

inline void Visualizer::setGLColor(int idx) { setGLColor(idx, 0); }

inline void Visualizer::setGLColor(float x, float y) { setGLColor(x,y,0); }

inline void Visualizer::setUsesAlpha(bool uses) { d_uses_alpha = uses; }

inline bool Visualizer::getUsesAlpha() const { return d_uses_alpha; }

inline void Visualizer::removeAllSeeds() {}

inline void Visualizer::seedGrid() {}

inline void Visualizer::setGlobalAlpha(float alpha) { d_global_alpha = alpha; }

inline float Visualizer::getGlobalAlpha() const {return d_global_alpha; }


#endif	/* VISUALIZER_H */

